//-1:向ArrayList和LinkedList加入10万个对象,比较性能;再随机删除100个,比较时间.
package Work0529;

import java.util.*;

public class ComparePerformance {

	public static void main(String[] args) {
		long a1 = System.nanoTime();
		List<People> a = new ArrayList<People>();
		String surname = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章";
		for (int p = 1; p <= 100000; p++) {
			int o = (int) (Math.random() * surname.length());
			a.add(new People(String.valueOf(surname.charAt(o)), o + 27, o + 150));
		}
		for (int i = 1; i <= 100; i++) {
			a.remove((int) (Math.random() * 100000));
		}
		long a2 = System.nanoTime();
		long a3 = a2 - a1;
		System.out.println("ArrayList用时" + a3);
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		long b1 = System.nanoTime();
		List<People> b = new LinkedList<People>();
		String surname1 = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章";

		for (int p = 1; p <= 100000; p++) {
			int o1 = (int) (Math.random() * surname.length());
			b.add(new People(String.valueOf(surname1.charAt(o1)), o1 + 27, o1 + 150));
		}
		for (int i = 1; i <= 100; i++) {
			b.remove((int) (Math.random() * 100000));
		}
		long b2 = System.nanoTime();
		long b3 = b2 - b1;
		System.out.println("LinkedList用时" + b3);
		System.out.println(b3 > a3 ? "ArrayList用时短" : "LinkedList用时短");
	}

}
